home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Documentation / Tech Notes & Articles / Recipes / Part Persistency / Creating a Part by Kind next >
Encoding:
Text File  |  1995-11-07  |  2.6 KB  |  67 lines  |  [TEXT/ttxt]

  1. OpenDoc™ Recipes
  2.  
  3. Creating a Part by Kind
  4. By The OpenDoc Design Team
  5. November 7th, 1995
  6.  
  7.  
  8. © 1993-1995  Apple Computer, Inc. All Rights Reserved.
  9. Apple, the Apple logo, and Macintosh are registered trademarks of Apple Computer, Inc.
  10. Mac and OpenDoc are trademarks of Apple Computer, Inc.
  11.  
  12.  
  13. Creating a part of a particular kind
  14.  
  15. OpenDoc provides the user many ways of embedding new content including drag & drop, and copy & paste.
  16. One traditional mechanism which applications have used to create new embedded content is a palette with a variety of kinds of content such as text, drawing, painting etc.  If your container part editor supports such a palette, then when the user chooses one of those abovementioned kinds of content and performs a gesture in your content area, you need to create a new part of the kind which the user has chosen.  This is a brief recipe showing the specific calls you need to make to do this.
  17.  
  18. Overview
  19.  
  20. There are are two thing your part editor needs to know how to do in order to properly implement this recipe.
  21. 1. How to check to see if an editor is installed which will support a specific kind (so that your editor can know to dim the palette item or enable it). The method EditorIsAvailableForKind provides this information.
  22. 2. How to create a new part of a particular kind.  The method CreatePartOfKind performs this function.
  23.  
  24. Caveats
  25.  
  26. • This code does not contain proper error checking.
  27. • This code assumes your part editor stores a reference to the session object in the field fSession.
  28. • This code assumes your part editor stores a reference to its partwrapper object in the field fSelf as documented in the "Part Init & Externalizing" recipe document.
  29.  
  30.  
  31. Sample Code
  32.  
  33. #include "Part.xh"
  34. #include "Draft.xh"
  35. #include "StorageU.xh"
  36. #include "ODBindng.xh"
  37.  
  38.  
  39.  
  40. ODBoolean CMyPart::EditorIsAvailableForKind(Environment* ev, ODISOStr kind)
  41. {
  42.     ODEditor editorID = fSession->GetBinding(ev)->ChooseEditorForPart(kODNULL, kind);
  43.  
  44.     ODBoolean editorAvailable = strcmp(editorID,kODBlackBoxHandlerOfLastResort);
  45.  
  46.     ODDisposePtr( editorID );
  47.  
  48.     return editorAvailable;
  49. }
  50.  
  51.  
  52. void CMyPart::CreatePartOfKind(Environment* ev, ODISOStr kind)
  53. {
  54.     ODDraft* draft = fSelf->GetStorageUnit(ev)->GetDraft(ev);
  55.     ODPart* newPart = draft->CreatePart(ev, kind, kODNULL);
  56.     newPart->Externalize(ev);
  57.  
  58.     // At This point your part editor needs to Create a new frame for the newPart, passing in your active
  59.     // display frame as the containing frame, and store the new frame as one of your embedded frames in your
  60.     // in-memory content data structure.
  61.  
  62.     // See the "Embedding a Frame" recipe document for the code necessary to create an embedded frame for
  63.     // the newly created part.
  64. }
  65.  
  66.